<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>学生添加</title>
		<script type="text/javascript" src="js/jquery-1.8.0.min.js">
</script>
		<style mce_bogus="1">
table {
	border-collapse: collapse;
}

td {
	border: 1px solid #f00;
}
</style>
		<script type="text/javascript">
function turnback() {
	window.location.href = "student.do";
}
function savestudent() {
	var user = $("#user").val();
	var pwd = $("#pwd").val();
	if (user == null || user == "" || pwd == null || pwd == "") {
		alert("请埴写姓名和密码！");
	} else {
		$.ajax( {
			type : "POST",
			url : "student.do?method=save",
			dataType : "json",
			data : {
				"user" : user,
				"psw" : pwd
			},
			success : function(data) {
				if (data.state == "success") {
					alert("添加成功！");
					window.location.href="student.do";
				} else {
					alert("添加失败！");
				}
			}
		});
<%--$.ajax( {--%>
<%--		type : "POST",--%>
<%--		url : "student.do?method=save",--%>
<%--		dataType : "json",--%>
<%--		data:{"user":user,"psw":pwd},--%>
<%--		success : function(data) {--%>
<%--			if (data.addstate == "true") {--%>
<%--				alert("添加成功！");--%>
<%--				--%>
<%--			} else {--%>
<%--				alert("添加失败！");--%>
<%--			}--%>
<%--		},--%>
<%--		error : function() {--%>
<%--			alert("网络连接出错！");--%>
<%--		}--%>
<%--	})--%>
	}
}
</script>
	</head>
	<body>
		<form method="post" action="student.do?method=save">
			<p align="center" style="color: red">
				添加学生信息
			</p>
			<table align="center">
				<tr>
					<td>
						姓名
					</td>
					<td>
						<input id="user" name="user" type="text" />
					</td>
				</tr>
				<tr>
					<td>
						密码
					</td>
					<td>
						<input id="pwd" name="psw" type="text" />
					</td>
				</tr>
				<tr>
					<td colSpan="2" align="center">
						<input type="button" value="提交" onclick="savestudent();" />
						<input type="button" onclick="turnback()" value="返回" />
					</td>
				</tr>
			</table>
		</form>
	</body>
</html>
